package com.jollychic.controller;


import com.jollychic.model.User;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by xusheng on 2019/4/18.
 */

@RestController //Rest控制器
public class HelloController {

    Logger logger=Logger.getLogger(HelloController.class);

    @Value("${server.port}")
    String serverPort;

    @RequestMapping("helloWorld")
    public String helloWorld(){
        String logMsg="\r\n日志打印\r\n";
        logMsg+="打印时间："+System.currentTimeMillis()+"\r\n";
        logMsg+="服务器端口："+serverPort+"\r\n";
        logger.info(logMsg);
        return "Hello,It's Spring Boot. "+logMsg;
    }

    /**
     * 接收json数据，返回json数据
     * @param user
     * @return
     */
    @RequestMapping("helloJson")
    public User helloJson(@RequestBody User user){
        System.out.println(user.getUserId());
        System.out.println(user.getUserName());
        return user;
    }
}
